<!DOCTYPE html>
<html lang="zh-Hans">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.3.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/blog/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/blog/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/blog/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/blog/images/logo.svg" color="#222">

<link rel="stylesheet" href="/blog/css/main.css">

<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&display=swap&subset=latin,latin-ext">
<link rel="stylesheet" href="/blog/lib/font-awesome/css/font-awesome.min.css">


<script id="hexo-configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    hostname: new URL('https://guodh.gitee.io/blog').hostname,
    root: '/blog/',
    scheme: 'Pisces',
    version: '7.7.1',
    exturl: false,
    sidebar: {"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},
    copycode: {"enable":true,"show_result":true,"style":null},
    back2top: {"enable":true,"sidebar":false,"scrollpercent":false},
    bookmark: {"enable":false,"color":"#222","save":"auto"},
    fancybox: false,
    mediumzoom: false,
    lazyload: false,
    pangu: false,
    comments: {"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},
    algolia: {
      appID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    },
    localsearch: {"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},
    path: 'search.xml',
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}
  };
</script>

  <meta name="description" content="一直以为数据库的使用仅仅是常见的索引优化，以及SQL语句的学习，在者就是在写update的操作的时候记得加上Spring的@Transactional注解。但是在这次的项目中，让我学到了很多我应该注意的细节。   大数据量的操作一定要通过分页去处理，即使是服务端内部的update，也需要自己写一个 while(num &gt; 200) {…} 这种方式去处理。 在加事务的时候，一定要记得减少事务">
<meta property="og:type" content="article">
<meta property="og:title" content="数据库MVCC、事务回滚">
<meta property="og:url" content="https://guodh.gitee.io/blog/2018/04/21/2018/2018-04-19/index.html">
<meta property="og:site_name" content="蛋蛋的小屋">
<meta property="og:description" content="一直以为数据库的使用仅仅是常见的索引优化，以及SQL语句的学习，在者就是在写update的操作的时候记得加上Spring的@Transactional注解。但是在这次的项目中，让我学到了很多我应该注意的细节。   大数据量的操作一定要通过分页去处理，即使是服务端内部的update，也需要自己写一个 while(num &gt; 200) {…} 这种方式去处理。 在加事务的时候，一定要记得减少事务">
<meta property="og:locale">
<meta property="og:image" content="https://olwr1lamu.qnssl.com/15242358301691.jpg">
<meta property="og:image" content="https://olwr1lamu.qnssl.com/15242648560948.jpg">
<meta property="og:image" content="https://olwr1lamu.qnssl.com/15243167048994.jpg">
<meta property="og:image" content="https://olwr1lamu.qnssl.com/15243162433823.jpg">
<meta property="article:published_time" content="2018-04-20T16:00:01.000Z">
<meta property="article:modified_time" content="2018-04-22T15:42:41.000Z">
<meta property="article:author" content="RunningEgg">
<meta property="article:tag" content="技术">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://olwr1lamu.qnssl.com/15242358301691.jpg">

<link rel="canonical" href="https://guodh.gitee.io/blog/2018/04/21/2018/2018-04-19/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome: false,
    isPost: true
  };
</script>

  <title>数据库MVCC、事务回滚 | 蛋蛋的小屋</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-meta">

    <div>
      <a href="/blog/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">蛋蛋的小屋</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
        <p class="site-subtitle">来了就看看吧，没有刀剑只有故事</p>
  </div>

  <div class="site-nav-toggle">
    <div class="toggle" aria-label="Toggle navigation bar">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>
</div>


<nav class="site-nav">
  
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/blog/" rel="section"><i class="fa fa-fw fa-home"></i>Home</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/blog/about/" rel="section"><i class="fa fa-fw fa-user"></i>About</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/blog/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>Archives</a>

  </li>
        <li class="menu-item menu-item-book">

    <a href="/blog/book/" rel="section"><i class="fa fa-fw fa-archive"></i>book</a>

  </li>
  </ul>

</nav>
</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content">
            

  <div class="posts-expand">
      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block " lang="zh-Hans">
    <link itemprop="mainEntityOfPage" href="https://guodh.gitee.io/blog/2018/04/21/2018/2018-04-19/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/blog/images/avatar.gif">
      <meta itemprop="name" content="RunningEgg">
      <meta itemprop="description" content="写下我的点点滴滴，写下我对这个世界的看法，还有我内心锁崇拜的技术">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="蛋蛋的小屋">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          数据库MVCC、事务回滚
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">Posted on</span>

              <time title="Created: 2018-04-21 00:00:01" itemprop="dateCreated datePublished" datetime="2018-04-21T00:00:01+08:00">2018-04-21</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">Edited on</span>
                <time title="Modified: 2018-04-22 23:42:41" itemprop="dateModified" datetime="2018-04-22T23:42:41+08:00">2018-04-22</time>
              </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <p>一直以为数据库的使用仅仅是常见的索引优化，以及SQL语句的学习，在者就是在写update的操作的时候记得加上Spring的@Transactional注解。但是在这次的项目中，让我学到了很多我应该注意的细节。</p>
<blockquote>
<ol>
<li>大数据量的操作一定要通过分页去处理，即使是服务端内部的update，也需要自己写一个 while(num &gt; 200) {…} 这种方式去处理。</li>
<li>在加事务的时候，一定要记得减少事务的颗粒度。把需要事务的操作，例如update才去加上事务。</li>
<li>不仅仅是要会使用@Transcation这种注解，在长事务中可以自己去使用Spring提供的TranscationTemplate的这种方式，手动来控制事务的颗粒度。</li>
</ol>
</blockquote>
<p>那么，以上都是一些工程实践的经验，但是如果不能了解事务的本质还是对于数据的理解不够深入，所以这一次来谈谈数据库的事务管理。</p>
<h2 id="MVCC-定义"><a href="#MVCC-定义" class="headerlink" title="MVCC 定义"></a>MVCC 定义</h2><p>MVCC 全称是 Multiversion concurrency control，多版本并发控制。<br>为什么会有这样一个概念呢？ 最初对于数据的控制最稳妥的方案就是顺序进行操作，这样只要保证只有一个用户操作资源，很好的避免了并发问题。但是，效率是极其低下的。</p>
<img src="https://olwr1lamu.qnssl.com/15242358301691.jpg" alt="不同阶段"/>

<p>于是，就有了两段锁 （2PL）类似java中的读写锁概念，由于数据库大量的操作都是读，能够很好的提升读的性能。但是呢，如果一个用户长时间持有写锁，也会导致读锁无法拿到。<br>于是乎，MVCC就出现了。当然，MVCC是一个相当成熟的理论，不同的数据库已经很好的实现了。甚至，如果你有兴趣你也可以自己动手实现一个，当然也有很好的例子可以借鉴。<br>下文是TiDB的对于MVCC的实现的讲解。</p>
<blockquote>
<p><a href="https://zhuanlan.zhihu.com/p/24118962">https://zhuanlan.zhihu.com/p/24118962</a></p>
</blockquote>
<p>顺便插一句，看一个数据库的实现架构还是很有帮助的，而且还是中文的，很棒。</p>
<p>下图是TiDB架构师来我们公司介绍的PPT所讲到的Tikv的逻辑结构层。我们可以看到，基于存储层和事务处之间，夹杂着MVCC的逻辑层。</p>
<img src="https://olwr1lamu.qnssl.com/15242648560948.jpg" width="40%" height="40%" alt="TIDB逻辑结构"/>

<h2 id="如何实现多版本"><a href="#如何实现多版本" class="headerlink" title="如何实现多版本"></a>如何实现多版本</h2><p>实现的方案有两种：版本号和时间戳；<br>只要保证每一次更新操作的序号都是递增的，进而来区分不同的操作。</p>
<h3 id="悲观锁-vs-乐观锁"><a href="#悲观锁-vs-乐观锁" class="headerlink" title="悲观锁 vs 乐观锁"></a>悲观锁 vs 乐观锁</h3><p>为啥这里突然会讲这个呢？因为市场上比较典型的数据库Mysql使用的是悲观锁，PostgreSQL使用的是乐观锁。<br>悲观锁认为冲突时常见的，所以在不同版本的数据之间，有某个版本的数据要进行更新的时候，这个数据就会被锁住。那么此时，无论是哪个版本的这条数据都将无法更新。所以，某种意义上来说Mysql并没有实现MVCC。<br>而PostgreSQL不同，它使用的是乐观锁，每个不同版本的数据都是可以进行操作的，只有在事务commit之前，数据库会对版本号进行校验，一旦发现有冲突的，就进行回滚。</p>
<h2 id="如何回滚数据"><a href="#如何回滚数据" class="headerlink" title="如何回滚数据"></a>如何回滚数据</h2><p>那么当发生冲突的时候怎么办？这就需要undo.log的帮助。undo.log中记录了，数据库发生回滚需要做的操作。</p>
<h3 id="undo和redo关系"><a href="#undo和redo关系" class="headerlink" title="undo和redo关系"></a>undo和redo关系</h3><p>既然说了undo.log，那么肯定要来说说redo.log。undo和redo是一对好基友，有undo就一定有redo（为什么这么肯定，往下看）。<br>undo是用来回滚数据库，而redo是为了保证数据宕机之后能够恢复到宕机前的瞬间。为什么需要redo呢？因为数据库有个将磁盘数据读到内存，在内存中进行处理的操作。如果此时数据库宕机就需要使用redo回到当时的瞬间。<strong>不过需要说明的是，此时的事务是需要回滚的，当把所有的redo做完之后，还需要依据undo进行事务的回滚。</strong></p>
<h3 id="实际操作"><a href="#实际操作" class="headerlink" title="实际操作"></a>实际操作</h3><p>假设有A、B两个数据，值分别为1,2，开始一个事务，事务的操作内容为：把1修改为3，2修改为4，那么实际的记录如下（简化）：</p>
<table>
<thead>
<tr>
<th></th>
<th>数据库操作</th>
<th>undo log</th>
<th>redo log</th>
</tr>
</thead>
<tbody><tr>
<td>1</td>
<td>begin;</td>
<td></td>
<td></td>
</tr>
<tr>
<td>2</td>
<td>-&gt;</td>
<td>update A=1</td>
<td></td>
</tr>
<tr>
<td>3</td>
<td>update A=3</td>
<td></td>
<td></td>
</tr>
<tr>
<td>4</td>
<td>-&gt;-&gt;</td>
<td></td>
<td>update A=3</td>
</tr>
<tr>
<td>5</td>
<td>-&gt;</td>
<td>update B=2</td>
<td></td>
</tr>
<tr>
<td>6</td>
<td>update B=4</td>
<td></td>
<td></td>
</tr>
<tr>
<td>7</td>
<td>-&gt;-&gt;</td>
<td></td>
<td>update B=4</td>
</tr>
<tr>
<td>8</td>
<td>commit;</td>
<td></td>
<td></td>
</tr>
</tbody></table>
<h3 id="优化处理"><a href="#优化处理" class="headerlink" title="优化处理"></a>优化处理</h3><p>而且，为了能够更好的处理redo.log和undo.log，InnoDb直接机智的把undo.log当做redo.log来处理。这样直接就能用一种格式的来处理这俩兄弟。处理的结果如下：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">记录<span class="number">1</span>: <span class="operator">&lt;</span>trx1, Undo log <span class="keyword">insert</span> <span class="operator">&lt;</span>undo_insert …<span class="operator">&gt;&gt;</span></span><br><span class="line">记录<span class="number">2</span>: <span class="operator">&lt;</span>trx1, <span class="keyword">insert</span> A…<span class="operator">&gt;</span></span><br><span class="line">记录<span class="number">3</span>: <span class="operator">&lt;</span>trx1, Undo log <span class="keyword">insert</span> <span class="operator">&lt;</span>undo_update …<span class="operator">&gt;&gt;</span></span><br><span class="line">记录<span class="number">4</span>: <span class="operator">&lt;</span>trx1, <span class="keyword">update</span> B…<span class="operator">&gt;</span></span><br><span class="line">记录<span class="number">5</span>: <span class="operator">&lt;</span>trx1, Undo log <span class="keyword">insert</span> <span class="operator">&lt;</span>undo_delete …<span class="operator">&gt;&gt;</span></span><br><span class="line">记录<span class="number">6</span>: <span class="operator">&lt;</span>trx1, <span class="keyword">delete</span> C…<span class="operator">&gt;</span></span><br><span class="line">记录<span class="number">7</span>: <span class="operator">&lt;</span>trx1, <span class="keyword">insert</span> C<span class="operator">&gt;</span></span><br><span class="line">记录<span class="number">8</span>: <span class="operator">&lt;</span>trx1, <span class="keyword">update</span> B <span class="keyword">to</span> <span class="keyword">old</span> <span class="keyword">value</span><span class="operator">&gt;</span></span><br><span class="line">记录<span class="number">9</span>: <span class="operator">&lt;</span>trx1, <span class="keyword">delete</span> A<span class="operator">&gt;</span></span><br></pre></td></tr></table></figure>
<p>同时，由于是顺序写，能大大的提升性能。</p>
<h2 id="Mysql版本问题"><a href="#Mysql版本问题" class="headerlink" title="Mysql版本问题"></a>Mysql版本问题</h2><p>那么就让我们开两个客户端来实验一下我们做的判断。</p>
<p>实验一：</p>
<table>
<thead>
<tr>
<th></th>
<th>客户端1操作</th>
<th>客户端2操作</th>
</tr>
</thead>
<tbody><tr>
<td>1</td>
<td>begin;</td>
<td></td>
</tr>
<tr>
<td>2</td>
<td></td>
<td>begin;</td>
</tr>
<tr>
<td>3</td>
<td></td>
<td>select * from test where id = 1; 结果aa</td>
</tr>
<tr>
<td>4</td>
<td>update test set name = ‘aa11’ where id = 1;</td>
<td></td>
</tr>
<tr>
<td>5</td>
<td></td>
<td>select * from test where id = 1; 结果aa</td>
</tr>
<tr>
<td>6</td>
<td>commit;</td>
<td></td>
</tr>
<tr>
<td>7</td>
<td></td>
<td>select * from test where id = 1; 结果aa</td>
</tr>
<tr>
<td>8</td>
<td></td>
<td>commit;</td>
</tr>
<tr>
<td>9</td>
<td></td>
<td>select * from test where id = 1; 结果aa11</td>
</tr>
</tbody></table>
<p>不知各位看官，看到实验一是否想到一个问题，为什么客户端1commit之后，客户端2还是不能够看到更新后的数据？因为Mysql默认实现的是可重复读，如果读到的数据每一次都有可能不一样，就违背了隔离级别的语义。</p>
<p>实验二：</p>
<table>
<thead>
<tr>
<th></th>
<th>客户端1操作</th>
<th>客户端2操作</th>
</tr>
</thead>
<tbody><tr>
<td>1</td>
<td>begin;</td>
<td></td>
</tr>
<tr>
<td>2</td>
<td></td>
<td>begin;</td>
</tr>
<tr>
<td>3</td>
<td>update test set name = ‘aa22’ where id = 1;</td>
<td></td>
</tr>
<tr>
<td>4</td>
<td></td>
<td>update test set name = ‘aa22’ where id = 1; 结果：超时</td>
</tr>
<tr>
<td>5</td>
<td></td>
<td>ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction</td>
</tr>
</tbody></table>
<h3 id="遇到死锁如何解决"><a href="#遇到死锁如何解决" class="headerlink" title="遇到死锁如何解决"></a>遇到死锁如何解决</h3><p>这里还可以通过别的方式来看我们想要的结果，当然如果遇到死锁的问题的时候，也是一个很好的查问题的方法。</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">show</span> engine innodb status;</span><br><span class="line"><span class="keyword">show</span> <span class="keyword">full</span> processlist; </span><br></pre></td></tr></table></figure>
<img src="https://olwr1lamu.qnssl.com/15243167048994.jpg" alt="show full processlist"/>

<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">-- information_schem库</span></span><br><span class="line"><span class="keyword">select</span> <span class="operator">*</span> <span class="keyword">from</span> INNODB_LOCKS;</span><br><span class="line"><span class="keyword">select</span> <span class="operator">*</span> <span class="keyword">from</span> INNODB_TRX;</span><br></pre></td></tr></table></figure>
<img src="https://olwr1lamu.qnssl.com/15243162433823.jpg" alt="select * from INNODB_LOCKS"/>


<h2 id="参考链接"><a href="#参考链接" class="headerlink" title="参考链接"></a>参考链接</h2><p>说说MySQL中的Redo log Undo log都在干啥: <a href="https://www.cnblogs.com/xinysu/p/6555082.html">https://www.cnblogs.com/xinysu/p/6555082.html</a><br>浅谈数据库并发控制 - 锁和 MVCC：<a href="https://draveness.me/database-concurrency-control">https://draveness.me/database-concurrency-control</a><br>MySQL 四种事务隔离级的说明：<a href="http://www.cnblogs.com/zhoujinyi/p/3437475.html">http://www.cnblogs.com/zhoujinyi/p/3437475.html</a></p>

    </div>

    
    
    

      <footer class="post-footer">
          <div class="post-tags">
              <a href="/blog/tags/%E6%8A%80%E6%9C%AF/" rel="tag"># 技术</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/blog/2018/03/11/2018/CMS%E6%94%B6%E9%9B%86%E5%99%A8vsG1%E6%94%B6%E9%9B%86%E5%99%A8/" rel="prev" title="CMS收集器 VS G1收集器">
      <i class="fa fa-chevron-left"></i> CMS收集器 VS G1收集器
    </a></div>
      <div class="post-nav-item">
    <a href="/blog/2018/05/03/2018/Solr%E5%AD%A6%E4%B9%A0%E6%80%BB%E7%BB%93/" rel="next" title="Solr AND SolrCloud 学习记录">
      Solr AND SolrCloud 学习记录 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  

  </div>


          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let activeClass = CONFIG.comments.activeClass;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          Table of Contents
        </li>
        <li class="sidebar-nav-overview">
          Overview
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#MVCC-%E5%AE%9A%E4%B9%89"><span class="nav-number">1.</span> <span class="nav-text">MVCC 定义</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%A6%82%E4%BD%95%E5%AE%9E%E7%8E%B0%E5%A4%9A%E7%89%88%E6%9C%AC"><span class="nav-number">2.</span> <span class="nav-text">如何实现多版本</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%82%B2%E8%A7%82%E9%94%81-vs-%E4%B9%90%E8%A7%82%E9%94%81"><span class="nav-number">2.1.</span> <span class="nav-text">悲观锁 vs 乐观锁</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%A6%82%E4%BD%95%E5%9B%9E%E6%BB%9A%E6%95%B0%E6%8D%AE"><span class="nav-number">3.</span> <span class="nav-text">如何回滚数据</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#undo%E5%92%8Credo%E5%85%B3%E7%B3%BB"><span class="nav-number">3.1.</span> <span class="nav-text">undo和redo关系</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%AE%9E%E9%99%85%E6%93%8D%E4%BD%9C"><span class="nav-number">3.2.</span> <span class="nav-text">实际操作</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E4%BC%98%E5%8C%96%E5%A4%84%E7%90%86"><span class="nav-number">3.3.</span> <span class="nav-text">优化处理</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Mysql%E7%89%88%E6%9C%AC%E9%97%AE%E9%A2%98"><span class="nav-number">4.</span> <span class="nav-text">Mysql版本问题</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E9%81%87%E5%88%B0%E6%AD%BB%E9%94%81%E5%A6%82%E4%BD%95%E8%A7%A3%E5%86%B3"><span class="nav-number">4.1.</span> <span class="nav-text">遇到死锁如何解决</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%8F%82%E8%80%83%E9%93%BE%E6%8E%A5"><span class="nav-number">5.</span> <span class="nav-text">参考链接</span></a></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">RunningEgg</p>
  <div class="site-description" itemprop="description">写下我的点点滴滴，写下我对这个世界的看法，还有我内心锁崇拜的技术</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/blog/archives/">
        
          <span class="site-state-item-count">89</span>
          <span class="site-state-item-name">posts</span>
        </a>
      </div>
      <div class="site-state-item site-state-tags">
        <span class="site-state-item-count">24</span>
        <span class="site-state-item-name">tags</span>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="mailto:guodh_1@163.com" title="E-Mail → mailto:guodh_1@163.com" rel="noopener" target="_blank"><i class="fa fa-fw fa-envelope"></i>E-Mail</a>
      </span>
  </div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2022</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">RunningEgg</span>
</div>
  <div class="powered-by">Powered by <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> v5.3.0
  </div>
  <span class="post-meta-divider">|</span>
  <div class="theme-info">Theme – <a href="https://pisces.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Pisces</a> v7.7.1
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="/blog/lib/anime.min.js"></script>
  <script src="/blog/lib/velocity/velocity.min.js"></script>
  <script src="/blog/lib/velocity/velocity.ui.min.js"></script>

<script src="/blog/js/utils.js"></script>

<script src="/blog/js/motion.js"></script>


<script src="/blog/js/schemes/pisces.js"></script>


<script src="/blog/js/next-boot.js"></script>




  















  

  

</body>
</html>
